package com.gwclh.personnel.controller;

import com.gwclh.personnel.bean.ResultVo;
import com.gwclh.personnel.service.IFileUploadService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/upload")
@Api(tags = "文件上传接口")
public class UploadController {

    @Autowired
    IFileUploadService fileUploadService;


    @PostMapping("/single/{type}")
    @ApiOperation(value = "单文件上传接口")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "文件",name = "file",dataType = "MultipartFile",paramType = "DataForm"),
            @ApiImplicitParam(value = "文件上传用途，1表示上传的是头像，其他表示文章缩略图等",name = "type",dataType = "Integer",paramType = "Path")
    })
    @RequiresAuthentication
    public ResultVo UploadSingleFile(@RequestParam(value = "file") MultipartFile file, @PathVariable(value = "type") Integer type){
        return fileUploadService.uploadSingleImage(file,type);
    }

    @PostMapping("/muti")
    @ApiOperation(value = "多文件上传")
    @ApiImplicitParam(value = "文件列表",name = "files",dataType = "MultipartFile[]",paramType = "FormData")
    public ResultVo uploadMutiFile(@RequestParam(value = "files") MultipartFile[] files){
        return fileUploadService.uploadMutiImage(files);
    }

}

